//
// Created by zhou on 2021/10/24.
//

#include <iostream>
using namespace std;


 struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode() : val(0), left(nullptr), right(nullptr) {}
      TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
      TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  };
class Solution {
public:

    TreeNode* mergeTrees(TreeNode* root1, TreeNode* root2) {
        if(root1== nullptr)return root2;
        if(root2== nullptr)return root1;

        auto merge=new TreeNode(root1->val+root2->val);

        merge->left= mergeTrees(root1->left,root2->left);
        merge->right= mergeTrees(root1->right,root2->right);



        return merge;
    }
};
int main(){
    TreeNode*p1=new TreeNode(2);
    TreeNode*p2=new TreeNode(2);
    TreeNode*root1=p1;
    TreeNode*root2=p2;
    p1->left=new TreeNode(3);
    p2->right=new TreeNode(9);
    Solution solution;
    TreeNode *p=solution.mergeTrees(root1,root2);
    cout<<p->val;
    cout<<p->left->val;
    cout<<p->right->val;

}
